package com.ruoyi.framework.web.websocket.vo;


import com.alibaba.fastjson2.JSONObject;

/**
 * 向前端推送消息的结构体
 */
public class WsMessage {
    public static final int HEART = 1000;
    public static final int SUBSCRIBE = 1001;
    public static final int UNSUBSCRIBE = 1002;
    public static final int ALARM = 1010;

    /** 消息类型  */
    private Integer type;

    /** 消息内容 */
    private String msg;

    /** 时间戳 **/
    private Long ts;

    /** 业务类型 **/
    private String objectType;
    /** 业务对象 **/
    private Long objectId;

    public static WsMessage create(Integer type, String msg, Long ts){
        WsMessage message = new WsMessage();
        message.type = type;
        message.msg = msg;
        message.ts = (ts == null ? System.currentTimeMillis() : ts) / 1000;
        return message;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    public Long getTs() {
        return ts;
    }

    public void setTs(Long ts) {
        this.ts = ts;
    }

    public String getObjectType() {
        return objectType;
    }

    public void setObjectType(String objectType) {
        this.objectType = objectType;
    }

    public Long getObjectId() {
        return objectId;
    }

    public void setObjectId(Long objectId) {
        this.objectId = objectId;
    }

    public String toJSONString(){
        return JSONObject.toJSONString(this);
    }

    @Override
    public String toString(){
        return toJSONString();
    }
}
